package org.trackcore.handler;

import org.springframework.stereotype.Component;
import org.trackcore.model.entity.PerformanceLCP;
import org.trackcore.service.PerformanceLCPService;
import org.trackcore.utils.DataUtils;

import java.util.Map;

@Component
public class PerformanceLCPHandler implements DataHandler {
    private final PerformanceLCPService service; // 使用新的Service

    public PerformanceLCPHandler(PerformanceLCPService service) {
        this.service = service;
    }

    @Override
    public String getHandlerKey() {
        return "performance_"; // 修改为lcp对应的key
    }

    @Override
    public void handle(Map<String, Object> data, String logId) {
        PerformanceLCP LCP = PerformanceLCP.builder()
                .logId(logId)
                .name(DataUtils.getString(data, "name")) // "first-paint"或"first-contentful-paint"
                .entryType(DataUtils.getString(data, "entryType"))
                .startTime(DataUtils.getDouble(data, "startTime"))
                .duration(DataUtils.getDouble(data, "duration"))
                .pageUrl(DataUtils.getString(data, "pageUrl"))
                .build();
        service.save(LCP);





        //dev落后
    }
}
